home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / zapem-0.000 / zapem-0 / zapem / projectile.cc < prev    next >
C/C++ Source or Header  |  1995-06-03  |  2KB  |  96 lines

  1. #include "btypes.h"
  2. #include "sprite.h"
  3. #include "weapon.h"
  4. #include "projectile.h"
  5. #include "effects.h"
  6.  
  7. extern int ticks;
  8.  
  9. Projectile :: Projectile( Sprite* anchor, int rate, int e, int m) 
  10. {
  11.     owner=anchor;
  12.     firerate=rate;
  13.     energy=e;
  14.     maxproj=m;
  15. }
  16.  
  17. void
  18. Projectile:: setSlot(int s)
  19. {
  20.     for(int i=0;i<maxproj;i++)
  21.         beam[i].setSlot(s);
  22. }
  23.  
  24. void 
  25. Projectile :: move(void)
  26. {
  27.     cerr << "moving proj\n";
  28.         for(int i=0;i<maxproj;i++)
  29.         {
  30.                 beam[i].move();
  31.                 if(beam[i].getYp() < 0)
  32.             beam[i].disappear();
  33.         }
  34. }
  35.  
  36. void
  37. Projectile :: fire(void)
  38. {
  39.     static int last=0;
  40.  
  41.     if(ticks - last > firerate)
  42.     { 
  43.             int i=0;
  44.             while(beam[i].getVisible()==1 && i<maxproj)
  45.                     i++;
  46.             if(i>=maxproj || beam[i].getVisible()==true)
  47.                     return;
  48.         sound(CHAN_PLAYER);
  49.             beam[i].setDelta(0,-2);
  50.             beam[i].setPos(owner->getXp()+owner->getWidth()/2-beam[i].getWidth()/2, owner->getYp()-beam[i].getHeight());
  51.             beam[i].appear();
  52.         last=ticks;
  53.     }
  54. }
  55.  
  56. bool
  57. Projectile :: collide(const Sprite& s)
  58. {
  59.     for(int i=0;i<maxproj;i++)
  60.     {
  61.         if(beam[i].getVisible())
  62.         {
  63.             if(beam[i].collide(s)) 
  64.             {
  65.                 beam[i].disappear();
  66.                 return true;
  67.             }
  68.         }        
  69.     }
  70.     return false;
  71. }
  72.  
  73. int
  74. Projectile :: getEnergy( void ) const
  75. {
  76.     return energy;
  77. }
  78.  
  79. void
  80. Projectile :: replace (void)
  81. {
  82.     /* no need as popgun is a sprite! */
  83. }
  84.  
  85. void
  86. Projectile :: getBack (void)
  87. {
  88.     /* no need as popgun is a sprite! */
  89. }
  90.  
  91. void
  92. Projectile :: paste (void)
  93. {
  94.     /* no need as popgun is a sprite! */
  95. }
  96.